package com.isoft.controller.sys;

import com.isoft.bean.Result;
import com.isoft.anno.SysControllerLogAnnotation;
import com.isoft.bean.OprateType;
import com.isoft.bean.ResponseData;
import com.isoft.bean.SysType;
import com.isoft.controller.BaseController;
import com.isoft.entity.CheckChange;
import com.isoft.entity.PageBean;
import com.isoft.service.impl.CheckChangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/sys/check")
public class CheckChangeController extends BaseController {
    @Autowired
    CheckChangeService checkChangeService;
    //分页查所有审核变更信息
    @GetMapping("/gets")
    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "10") Integer pageSize)
    {
        log.info("分页查询 ：{},{}" , page , pageSize);
        PageBean pageBean = checkChangeService.getAll(page , pageSize);
        return Result.success(pageBean);
    }
    //修改审核状态 --0未审核--1已通过--3已驳回
    @SysControllerLogAnnotation(sysType = SysType.SYSTEM, operateType = OprateType.REVIEW, desc = "变更审核状态修改--已通过")
    @PutMapping("/permit/{id}")
    public ResponseData<Boolean> yetPermitYes(@PathVariable Integer id){
        return  returnBoolean(checkChangeService.yetPermitYes(id));
    }
    //修改审核状态 --0未审核--1已通过--3已驳回
    @SysControllerLogAnnotation(sysType = SysType.SYSTEM, operateType = OprateType.REVIEW, desc = "变更审核状态修改--已驳回")
    @PutMapping("/unpermit/{id}")
    public ResponseData<Boolean> yetPermitNo(@PathVariable Integer id){
        return  returnBoolean(checkChangeService.yetPermitNo(id));
    }
    //添加审核变更信息
    @SysControllerLogAnnotation(sysType = SysType.SYSTEM, operateType = OprateType.INSERT, desc = "插入审核变更数据")
    @PostMapping("/add")
    public ResponseData<Boolean> addChange(@RequestBody CheckChange checkChange){
        return  returnBoolean(checkChangeService.add(checkChange));
    }
}
